package com.nbsaas.boot.contoller;

import com.nbsaas.boot.app.api.apis.AppRoleApi;
import com.nbsaas.boot.app.api.domain.request.AppRoleRequest;
import com.nbsaas.boot.app.api.domain.request.AppRoleSearch;
import com.nbsaas.boot.app.api.domain.response.AppRoleResponse;
import com.nbsaas.boot.app.api.domain.simple.AppRoleSimple;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 *  对外控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/appRole")
public class AppRoleController {


    @Resource
    private AppRoleApi appRoleApi;


    @RequiresPermissions("appRole")
    @RequestMapping("/search")
    public PageResponse<AppRoleSimple> search(@RequestBody AppRoleSearch request) {
        return appRoleApi.search(request);
    }

    @RequiresPermissions("appRole")
    @RequestMapping("/list")
    public ListResponse<AppRoleSimple> list(@RequestBody AppRoleSearch request) {
        return appRoleApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("appRole")
    @CreateData
    @RequestMapping("/create")
    public ResponseObject<AppRoleResponse> create(@RequestBody @Validated(AddOperator.class) AppRoleRequest request) {
        return appRoleApi.create(request);
    }

    @RequiresPermissions("appRole")
    @UpdateData
    @RequestMapping("/update")
    public ResponseObject<AppRoleResponse> update(@RequestBody @Validated(UpdateOperator.class) AppRoleRequest request) {
        return appRoleApi.update(request);
    }

    @RequiresPermissions("appRole")
    @RequestMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) AppRoleRequest request) {
        return appRoleApi.delete(request);
    }

    @RequiresPermissions("appRole")
    @RequestMapping("/view")
    public ResponseObject<AppRoleResponse> view(@RequestBody @Validated(ViewOperator.class) AppRoleRequest request) {
        return appRoleApi.view(request);
    }
}